import { message } from 'antd';
import { submitForm,queryScreen,fontFamily, fontSizeList,preview} from '@/services/bnsConfig/screen';

export default {
  namespace: 'screenForm',
  state: {
    // 列表数据
    data: {
      dataList: [],
    },
    queryForm:{},

  },

  effects: {
    *queryList({ payload, callback }, { call, put }) {
      const response = yield call(queryScreen, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *submit({ payload, callback }, { call, put }) {
      const response = yield call(submitForm, payload);
      yield put({
        type: 'saveSubmit',
        payload: response,
      });
      if (callback) callback(response);
    },

    //字体
    *fontFamily({ payload, callback }, { call, put }) {
      const response = yield call(fontFamily, payload);
      yield put({
        type: 'font',
        payload: response,
      });
      if (callback) callback(response);
    },

//字号
    *fontSizeList({ payload, callback }, { call, put }) {
      const response = yield call(fontSizeList, payload);
      yield put({
        type: 'fontSize',
        payload: response,
      });
      if (callback) callback(response);
    },
    *preview({ payload, callback }, { call, put }) {
        const response = yield call(preview, payload);
        yield put({
          type: 'savepreview',
          payload: response,
        });
        if (callback) callback(response);
      },
    
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },

    font(state, action) {
      return {
        ...state,
        fontData: action.payload.data.dataList,
      };
    },

    fontSize(state, action) {
      return {
        ...state,
        fontSizeData: action.payload.data.dataList,
      };
    },
  },

};
